home *** CD-ROM | disk | FTP | other *** search
Text File | 1980-01-06 | 35.2 KB | 1,005 lines |
- >>
- <<
- >>>
- &
- &&
- |
- ||
- %
- Access control
- API
- Applet
- Application
- Array
- Boolean
- Break
- Byte
- Bytecode
- Cast
- Char
- Class
- Compiler
- Constructor
- Continue
- Detour
- Do
- Event
- Exception handling
- Expression
- FAQ
- Field
- Field Method
- Field Variable
- Final
- For
- Frame
- Hash table
- HTML
- If
- Inheritance
- Integer
- Interpreter
- Java
- Javac
- Java API
- Layout manager
- Long
- Method
- Multi-threading
- Object-oriented programming
- Override
- Package
- Parameter
- Pass by reference
- Pass by value
- Private
- Protected
- Public
- Reference
- Return
- Short
- Stack
- Static
- Stream
- String
- Synchronized
- Switch
- Talk Java to Me
- Telecommunications
- Thread
- Variable
- Vector
- While
- *>>
- This is a Java operator which shifts the bits of a numeric value to the right. It duplicates
- the left-most bit, which is the sign bit, as it shifts. So, an integer of 256, which is 0x00000100 in
- hex, can be right-shifted one position with "256 >> 1", which gives the value 128 or 0x00000080. An
- integer of -256, which is 0xffffff00 in hex, can be right-shifted with "256 >> 1" which gives the value
- -128 or 0xffffff80.
-
- The ">>>" operator performs a similar function, but always adds zero bits on the left-hand
- end, rather than duplicating the left-most bit.
- *<<
- This is a Java operator which shifts the bits of a numeric value to the left. It adds zero bits
- on the right-hand end as it shifts. So, an integer of 256, which is 0x00000100 in
- hex, can be left-shifted one position with "256 << 1", which gives the value 512 or 0x00000200. An
- integer of -256, which is 0xffffff00 in hex, can be left-shifted with "256 << 1" which gives the value
- -512 or 0xfffffe0.
- *>>>
- This is a Java operator which shifts the bits of a numeric value to the right. It adds zero bits
- on the left-hand end as it shifts. So, an integer of 256, which is 0x00000100 in
- hex, can be right-shifted one position with "256 >>> 1", which gives the value 128 or 0x00000080.
-
- This operator is also known as the "unsigned right-shift operator" because it is usually applied
- only to unsigned values. That is because the sign bit will always become zero as a result of using
- this operator, which means the resulting value will always be positive.
-
- The ">>" operator performs a similar function, but always duplicates the left-most bit (the sign
- bit) as it shifts. That makes it more appropriate for use with signed values.
- *&
- This is the "bitwise and" operator. It "ands" two operands together, one bit at a time. For
- example, if you had the values 0x0000ffff and 0x10101010, you could "and" them together with
- "0x0000ffff & 0x10101010", which would result in the value "0x00001010".
-
- This operator is easily confused with the "&&" operator, which performs a "logical and". That
- means it "ands" two boolean values (values of "true" or "false"), rather than two numeric values.
- The two operators seem similar, but are quite different, and are not interchangable.
- *&&
- This is the "logical and" operator. It "ands" two boolean values together. For example, you
- might have the expression "a == 5", which results in a boolean ("true" or "false") value; you might
- also have the expression "b > 0", which also results in a boolean value. You can determine if
- both values are true by "and'ing" them together with the expression "(a == 5) && (b > 0)". The
- result will be "true" if both of the sub-expressions is true; otherwise, it will be false.
-
- This operator is easily confused with the "&" operator, which performs a "bitwise and". That means
- it "ands" two numeric values together, one bit at a time. These two operators seem similar,
- but are quite different, and are not interchangeable.
- *|
- This is the "bitwise or" operator. It "ors" two operands together, one bit at a time. For
- example, if you had the values 0x0000ffff and 0x10101010, you could "or" them together with
- "0x0000ffff | 0x10101010", which would result in the value "0x1010ffff".
-
- This operator is easily confused with the "|" operator, which performs a "logical or". That
- means it "ors" two boolean values (values of "true" or "false"), rather than two numeric values.
- The two operators seem similar, but are quite different, and are not interchangable.
- *||
- This is the "logical or" operator. It "ors" two boolean values together. For example, you
- might have the expression "a == 5", which results in a boolean ("true" or "false") value; you might
- also have the expression "b > 0", which also results in a boolean value. You can determine if
- either (or both) values are true by "or'ing" them together with the expression "(a == 5) || (b > 0)". The
- result will be "true" if either (or both) of the sub-expressions are true; otherwise, it will be false.
-
- This operator is easily confused with the "|" operator, which performs a "bitwise or". That means
- it "ors" two numeric values together, one bit at a time. These two operators seem similar,
- but are quite different, and are not interchangeable.
- *%
- This is Java's "remainder" operator. It returns the remainder left after an integer division. For
- example, "7 % 3" has a value of 1, because "7 / 3" is 2 with a remainder of 1.
- *Access control
- This refers to controlling which parts of a program have access to certain field variables or
- methods of a class. For example, a field variable might be declared as "private", which means
- it can be used only by members of the class in which it is declared.
-
- There are several different access levels provided by Java, which are summarized in Figure XXX
- in the "Talk Java to Me" book.
- *API
- This stands for "application program interface", and is a general term refering to the way in
- which a program uses a set of functions.
-
- The "Java API" refers to the set of standard classes which are part of Java.
- *Applet
- This is a small Java program which normally is part of a World Wide Web page. The Java code is
- automatically executed when the Web page is displayed by a Java-capable Web browser, which can
- add animation or interactivity to a Web page.
-
- A more precise definition would be a piece of Java code which consists of a sub-class of the
- Applet class. The "Applet" class is one of the standard Java classes.
-
- Another kind of Java program is an "application". An
- "applet" is different from an "application" in that an "applet" is generally part of some larger
- whole, most commonly a Web page, and is executed as a "side effect" of opening that page. An
- "application", on the other hand, is a piece of Java code
- which can be complete by itself, and which is executed directly by the user.
- *Application
- This is a Java program which is run directly by the user. It often is a complete program
- by itself, needing no other code to execute.
-
- Another kind of Java program is an "applet". An
- "applet" is different from an "application" in that an "applet" is generally part of some larger
- whole, most commonly a Web page, and is executed as a "side effect" of opening that page. An
- "application", on the other hand, is a piece of Java code
- which can be complete by itself, and which is executed directly by the user.
- *Array
- An "array" is simply a series of
- values, that are treated as a group. For example, you might have a
- vector that is 10 integers, each of which represents the age of an employee. You could
- declare the vector like this:
-
- int ages[10] = {18,18,35,53,39,39,27,44,42,60};
-
- You could calculate the average age like this:
-
- float average;
- int sum = 0;
- int i;
-
- for (i=0; i<10; ++i) {
- sum += ages[i];
- }
-
- average = sum / 10;
-
- In addition to being a synonym for "array", "vector" can also refer to
- an object of the "Vector" class. The "vector" class is one of the standard
- Java classes, and provides a way to create arrays that can have varying sizes.
- *Boolean
- One of the basic Java data types, a "boolean" always has a value of either "true" or "false".
-
- The following example declares the variable "a" to be a boolean, and assigns a value of "true" to it:
-
- boolean a;
- a = true;
- *Break
- This is a Java statement which causes the loop it is contained within to be exited. The "loop"
- can be a "for", "while", or "do" loop. For example, the following use of the statement causes
- the loop to end if the "sum" exceeds 100:
-
- int sum = 0;
- int i;
-
- for (i=0; i<100; ++i) {
- sum += i*i;
- if (sum > 100) {
- break;
- }
- }
-
- It can also be used in a "switch" statement to exit from one of the cases:
-
- switch (a) {
-
- case 10:
- b = 5;
- break;
-
- case 20:
- b = 6;
- c = false;
- break;
-
- }
- *Byte
- In general, this is a set of 8 bits of computer memory. In a Java program, it is also
- one of the basic Java data types, which is 8 bits in length. It can be treated like a
- small integer:
-
- byte a;
-
- a = (byte)5*c;
-
- Note that a "byte" is not the same thing as a character. In Java, characters are stored
- in Unicode format, which means each character takes 16 bits of storage. Characters are
- normally stored using the "char" and "String" types.
- *Bytecode
- This is the form in which a compiled Java program is stored.
-
- When you write a Java program, you write it in source form. You then run a Java compiler
- (such as "javac") against it, creating a "bytecode file". This is the same program,
- but in a form that is easier for the Java interpreter to use. The Java interpreter can
- then be used to execute the bytecode file.
-
- By Java convention, bytecode files always end with the extension ".class".
- *Cast
- This is the process of converting one data type to another. For example, the Java
- expression "5 * c" will yield an integer value if "c" is an integer. To assign that
- value to a "short" variable, you must "cast" the value into a short, like this:
-
- int c = 12;
- short a;
-
- a = (short)(5 * c);
-
- It is generally legal to cast any of the native Java data types to another, although
- there are a few exceptions (such as casting a numeric value into a boolean).
-
- It is also possible to cast an object into a different class, but this requires that
- the resulting class be a sub-class or super-class of the original class.
- *Char
- This is one of the native Java data types. It is normally used to hold a single
- character. Because characters are stored using Unicode in Java, each character
- requires 16 bits of storage.
-
- For example, the following code creates a "char" variable, and stores the letter "a"
- in it:
-
- char c;
-
- c = 'a';
- *Class
- A "class" defines certain data ("field variables"), and processes ("field methods")
- which can be performed on that data.
-
- For example, the following class defines the data required to store a date, and
- a method that will assign a value to that date:
-
- public class date {
-
- int year;
- int month;
- int day;
-
- void Set(int y,int m,int d) {
- day = d;
- month = m;
- if (y > 99) {
- year = y;
- } else if (y >= 90) {
- year = 1900 + y;
- } else {
- year = 2000 + y;
- }
- }
-
- }
-
- Once a class like this is defined, it can be used to create "objects" of the
- class (e.g., to create "dates") like this:
-
- date a;
-
- The "methods" in the class can be used to perform operations on these objects:
-
- a.set(2010,10,10);
- *Compiler
- In the case of Java, this is a utility which converts a Java program from the form
- in which it was written by a human ("source" form) into the form used when it is
- run by a Java interpreter ("bytecode" form).
-
- One common Java compiler is provided as part of the Java Developer's Kit, and is
- named "javac". That compiler, along with the rest of the Java Developer's Kit, is
- included on this CD-ROM.
- *Constructor
- When a Java class is declared, it will generally include several "methods", which
- can be used to process the data ("field variables") in the class.
-
- A "constructor" is a special kind of "method".
-
- It is special because it is not used to process an object that already exists (like the
- other methods are), but rather is used to initialize a new object when that
- object is created.
-
- For example, you might have the class:
-
- public class Date {
-
- int year;
- int month;
- int day;
-
- Date(int y) {
- day = 1;
- month = 1;
- year = y;
- }
-
- void Set(int y,int m,int d) {
- day = d;
- month = m;
- year = y;
- }
-
- }
-
- This class has two methods: "Set" and "Date"; only "Date" is a constructor. It would
- be called when you create a new Date object, like this:
-
- Date a;
-
- a = new Date(2010);
- *Continue
- This is a Java statement which can be used to continue the execution of a loop, but to
- end the current iterration of that loop.
-
- For example:
-
- for (i=0; i<20; ++i) {
- sum += i;
- if (product > 50) {
- continue;
- }
- product *= i;
- }
-
- The "continue" statement here would prevent the repetition of the statement "product *= i" once
- the product reached a value of 50 or more. But, since the "continue" statement won't effect
- the "sum += i" statement, it will be performed as long as the "for" loop runs.
- *Detour
- This is one of the buttons on the control panel in this CD-ROM. It is used
- to allow you to skip certain topics which may not be of interest to everyone.
-
- The button is disabled during much of the CD, because the topics being covered are
- considered to be important to anyone planning to program in Java. When an optional
- topic begins, the narrator will tell you it's optional, and the detour button
- will become enabled.
- *Do
- This is one of the looping statements in Java. For example:
-
- do {
- sum *= 1.01;
- ++i;
- } while (i < 10);
-
- This will cause the statements "sum *= 1.01;" and "++i;" to be executed over and
- over, as long as "i" remains less than "10".
-
- A similar loop is:
-
- while (i < 10) {
- sum *= 1.01;
- ++i;
- }
-
- The second loop is almost idential to the first. The only difference is that the
- first loop will always execute the statements "sum *= 1.01;" and "++i" at least once,
- regardless of the initial value of "i". The second loop, on the other hand, would
- never execute the statements if "i" is at least 10 when the loop begins.
- *Event
- An event in Java means the same thing it does in the real world: "something
- happened". In the case of a Java program, the sorts of things that can happen
- are things like "the mouse was pressed down", "the mouse moved", "a key was
- pressed", etc.
-
- A Java program can have methods that are automatically called when an event
- occurs. For example, if you sub-class the "Applet" class, and override the method
- "mouseDown", your method will be called when the user presses down the mouse
- inside the Applet:
-
- public class myApplet extends Applet {
-
- mouseDown(Event e,int x,int y) {
- /* handle the event here */
- }
-
- }
- *Exception handling
- In most cases, you can think of this as "error handling". It refers to the
- way Java programs identify and route information to deal with an error.
-
- A simple example would be:
-
- try {
- myMethod(a);
- } catch (IllegalArgumentException e) {
- System.out.println("I've located too many widgets");
- System.exit(0);
- }
-
- This will try to execute the method "myMethod". If it fails due to
- an illegal argument, the calls to "System.out.println" and "System.exit" will
- be made.
-
- Within "myMethod", you might indicate an error as follows:
-
- void myMethod(int a) {
- if (a > 5) {
- throw new IllegalArgumentException();
- }
- sum += a;
- }
-
- For more details, see lesson 9 which discusses exception handling.
- *Expression
- This is a basic building block of most languages, including Java. It consists
- of a series of literal values like "5" or "1.23", combined with a series
- of variables like "sum" and "a", held together with operators like "+" and "*".
-
- For example, these are expressions:
-
- a
- 5
- a * 5
- ++a
- (a > 5 ? ((4 & b) | (8 & c)) : (d >> (e-3)))
-
- The parts of an expression are literals (like "5" or "1.23"), variables (like "a"
- or "b") and operators (like "*" or "&").
- *FAQ
- This stands for "frequently asked question". It is a general term used with
- computers. In the case of this CD, it is also a folder you can open to
- view frequently-asked questions (and their answers).
- *Field
- This is a part of a class.
-
- Fields come in two types: "field variables" and "field methods".
-
- For example:
-
- public class Date {
-
- int year;
- int day;
- int month;
-
- Date(int y) {
- day = 1;
- month = 1;
- year = y;
- }
-
- void Set(int y,int m,int d) {
- day = d;
- month = m;
- year = y;
- }
-
- }
-
- This class includes 5 fields: "year", "day", and "month" are "field variables",
- and "Date" and "Set" are "field methods".
-
- "Field variables" are the data which make up an object, and "field methods" are
- the processes you can perform on those objects.
- *Field Method
- This is part of a class which defines a process to be performed on an
- object of the class.
-
- For example:
-
- public class Date {
-
- int year;
- int day;
- int month;
-
- void Set(int y,int m,int d) {
- day = d;
- month = m;
- year = y;
- }
-
- }
-
- This class includes "Set", which is a "field method". It allows you to set the
- date for a date object.
-
- "Field methods" are normally called just "methods".
- *Field Variable
- This is a variable which is part of a class. For example:
-
- public class Date {
-
- int year;
- int day;
- int month;
-
- void Set(int y,int m,int d) {
- day = d;
- month = m;
- year = y;
- }
-
- }
-
- This class includes "year", "day", and "month", all of which are "field variables".
- *Final
- This is a keyword which indicates that a variable may not have its value changed. For
- example:
-
- public class Date {
-
- final int maxMonth 12
-
- int year;
- int day;
- int month;
-
- }
-
- The variables "year", "month", and "day" can all be modified; the variable
- "maxMonth" cannot.
-
- The keyword can also be used on methods. In that case, it indicates that the
- method cannot be overrided in sub-classes.
- *For
- This is a statement in Java which performs a loop. For example:
-
- for (i=0; i<5; ++i) {
- System.out.println(i);
- }
-
-
- This will cause the following output:
-
- 0
- 1
- 2
- 3
- 4
- *Frame
- What Java calls a "frame" would, in many environments, be called a "window". One
- of the standard Java classes is the "Frame" class, which allows a Java program
- to create a "frame" or "window".
-
- For information on how to use Java's Frame class, see Lesson 6.
- *Hash table
- This a common data structure which acts as an index for a series of objects. Each
- 0bject entered in the hash table is identified with a unique "key". The index can
- later be searched for a given key, and if the key is in the table the corresponding object
- will be returned.
-
- In Java, there is a "HashTable" class in the standard Java library. For information
- on how to use it, see Lesson 11.
- *HTML
- Pages on the World Wide Web are constructed using a special language called "HTML" which
- stands for "Hyper Text Markup Language". This is a very simple language which allows
- you to indicate what text and graphics should appear on the page, and what special characteristics
- (such as "bold" or "indented") it should have.
-
- HTML can also be used to identify a Java applet which should be included on the
- page. For information on how to do this, see Lesson 4.
- *If
- This is a Java statement which allows you to perform a test. Depending upon the
- results of that test, some additional Java code will either be executed or skipped.
-
- For example:
-
- if (a > 5) {
- b = 6;
- }
-
- Here the test is "a > 5". If the test is true, the statement "b = 6;" will be
- executed.
- *Inheritance
- When a Java class is declared, it can be identified as being a "sub-class" of
- another class. Being a "sub-class" means the new class can use all the field
- variables and methods of the "super class", but it can also add its own
- field variables and methods. This, in effect, allows you to create a
- special variation of the "super class".
-
- The act of using a field variable or method from the "super class" is called
- "inheriting" the variable or method.
- *Integer
- This is one of the basic data types in Java. It is an integer (i.e., "whole number")
- which can range from -2,147,483,648 to 2,147,483,647, and takes 32 bits of storage.
-
- For example, the following code declares an integer variable and assigns it a value:
-
- int a;
-
- a = 1047;
- *Interpreter
- After you write a Java program, you run it through a program called a "compiler". In
- the case of Java, one of the common compilers is named "javac". A Java compiler will
- translate the program into a special format called "bytecode".
-
- To execute the program, the "bytecode" file is processed by a program called an "interpreter". It
- carries out the instructions contained in the "bytecode" file similarly to the way
- a processor carries out instructions in an ".exe" file.
- *Java
- A computer programming language developed by Sun Microsystems.
-
- The name "Java" doesn't stand for anything, and it's not someone's name. Rather, it
- projects the kind of "hip" and "energetic" image that the developers wanted to have.
- *Java API
- The "Java API" refers to the set of standard classes which are part of Java.
-
- "API" is a general programming term which stands for "application programming interface". It can
- refer to the set of rules used to use any set of functions from a program.
- *Javac
- The "javac" compiler is the most common Java compiler, and is part of the Java Development Kit
- written by Sun Microsystems. This compiler, along with the rest of the Java Development Kit,
- are included on this CD-ROM.
- *Layout manager
- A "layout manager" is a class which determines the position and size of a control (or other object)
- within an area of the display (such as a frame or panel).
-
- There are several layout managers included in the standard Java classes, including the "GridLayoutManager"
- and the "FlowLayoutManager". It is also possible to write your own layout manager by creating a
- subclass of the "LayoutManager" class.
- *Long
- This is one of the basic Java data types. It holds integers (i.e., "whole numbers") which
- can range from about -9,000,000,000,000,000,000 to 9,000,000,000,000,000,000. Each
- long variable takes 64 bits of storage.
- *Method
- This is part of a class which defines a process to be performed on an
- object of the class.
-
- For example:
-
- public class Date {
-
- int year;
- int day;
- int month;
-
- void Set(int y,int m,int d) {
- day = d;
- month = m;
- year = y;
- }
-
- }
-
- This class includes "Set", which is a "method". It allows you to set the
- date for a date object.
-
- "Methods" are sometimes called "field methods".
- *Multi-threading
- This refers to having more than one "thread" in a program. Each "thread" runs independently
- of the other threads in the program, and runs at the same time. This can allow
- different parts of the program to be running simultaneously, or can allow the same part
- of the program to be running more than once simultaneously.
-
- For more information on "threads", see Lessons 5 and 11.
- *Object-oriented programming
- This is a way of programming in which the program is broken into parts called "classes". Each "class"
- describes a certain kind of object. The description of that kind of object consists of defining
- what data must be stored for it, and what processes can be performed on it.
-
- The power of object-oriented programming comes from many characteristics, but perhaps chief among
- them is that it allows pieces of code from one program to be easily and seamlessly re-used in
- another program.
-
- For a complete introduction to object-oriented programming, see Lesson 3.
- *Override
- When you define a class, you can declare it to be a "sub-class" of another class. That other
- class is known as the "super-class".
-
- The advantage of doing this is that you can use the field variables and methods of the super-class, but
- add your own field variables and methods to it. This allows you to use the parts of the super-class
- that apply, but to customize it where appropriate.
-
- While methods from the super-class are often used in the sub-class without change (i.e., they are
- "inherited"), they are sometimes replaced with different methods. This replacement is
- known as "overriding" the method. (The same thing can be done with field variables, although
- that is less common.)
- *Package
- This is a collection of classes that work in concert. They are generally placed in a separate
- directory, and are identified as belonging to the same package with the "package" statement.
-
- Putting classes together into a package is largely a matter of convenience, since it gives a clear
- structure to users and makes it easy for them to import the package into their programs. It also
- increases the access that members of the package have to other members and field variables in the package.
- *Parameter
- This is an item sent to a method. The item can be either a variable of one of the standard
- Java data types (e.g., "int"), or it can be an object (e.g., "String").
- *Pass by reference
- There are two ways data can be sent to a method.
-
- The first, "pass by reference", means that you
- are sending the location of the piece of data. This means there is only one copy of the data, and
- that if the method modifies it, the modification will be visible to the code that called the method.
-
- The other method is "pass by value". In this approach, a copy is made of the data, and that copy
- is sent to the method. This means that if the method changes the data, the original copy will remain
- intact, so the modification will be invisible to the code that called the method.
-
- Java uses "pass by reference" for any objects or arrays sent to methods. It uses "pass by value"
- for native data types (e.g., "int" or "float") sent to methods.
-
- The difference between these is important to understand so you will know what to expect when
- a method you are writing modifies one of the parameters sent to it.
- *Pass by value
- There are two ways data can be sent to a method.
-
- The first, "pass by reference", means that you
- are sending the location of the piece of data. This means there is only one copy of the data, and
- that if the method modifies it, the modification will be visible to the code that called the method.
-
- The other method is "pass by value". In this approach, a copy is made of the data, and that copy
- is sent to the method. This means that if the method changes the data, the original copy will remain
- intact, so the modification will be invisible to the code that called the method.
-
- Java uses "pass by reference" for any objects or arrays sent to methods. It uses "pass by value"
- for native data types (e.g., "int" or "float") sent to methods.
-
- The difference between these is important to understand so you will know what to expect when
- a method you are writing modifies one of the parameters sent to it.
- *Private
- Java provides the ability to control what access certain types of methods will have
- to certain field variables or methods of a class. For example, a field variable declared as
- "private" can be accessed only by members of the class in which the variable is declared.
-
- In addition to "private", there are several other access levels. Their effects are summarized
- in Figure XXX in the "Talk Java to Me" book.
- *Protected
- Java provides the ability to control what access certain types of methods will have
- to certain field variables or methods of a class. For example, a field variable declared as
- "protected" can be accessed only by members of the class in which the variable is declared, or
- by sub-classes of that class, or by other methods in the same package.
-
- In addition to "protected", there are several other access levels. Their effects are summarized
- in Figure XXX in the "Talk Java to Me" book.
- *Public
- Java provides the ability to control what access certain types of methods will have
- to certain field variables or methods of a class. For example, a field variable declared as
- "public" can be accessed by any method.
-
- In addition to "public", there are several other access levels. Their effects are summarized
- in Figure XXX in the "Talk Java to Me" book.
- *Reference
- Objects in Java are accessed by "reference". This means that when you declare a variable for
- an object, that variable can "reference" any object, and can be assigned to reference different
- ones at different times.
-
- For example, this code declares two variables of the Date class:
-
- Date a,b;
-
- And this code creates a "Date" object, and assigns the variable "a" to reference that object:
-
- a = new Date();
-
- If you wish, you can cause "b" to reference the same object with:
-
- a = b;
-
- Now a change to EITHER of the variables effects the same object. For example, you might set the
- month with:
-
- a.setMonth(10);
-
- That changes the month for both variables, since they reference the same object.
-
- This code would then create a second object, and cause "a" to reference it:
-
- a = new Date();
-
- But, "b" will still reference the first object.
- *Return
- This statement causes the execution of a method to end, and the calling method to resume.
-
- If the method has a return type other than "void", the "return" statement also indicates
- what value is to be returned by the method. For example:
-
- return;
-
- would be used in a method without a return type. But:
-
- return 5;
-
- might be used in a method with a return type of "int".
- *Short
- This is one of the basic Java data types. It is used to hold integers (i.e., "whole numbers")
- which range from -32,768 to 32,767. Each "short" takes 16 bits of storage.
- *Stack
- This is a standard programming data structure. Objects can be placed on a "stack" in much the
- same way that dishes are placed on a stack of dishes. The can be "pushed" onto the stack (i.e.,
- placed on the top of the stack) or "popped" off the stack (i.e., removed from the top).
-
- One of the standard set of Java classes is the "Stack" class. For more information on it,
- see Lesson 11.
- *Static
- A field variable normally exists once for each object. For example, if you have
- a class like this:
-
- public class Date {
-
- int Year;
- int Month;
- int Day;
- static int MonthMax;
-
- }
-
- there will be a "year" integer for every "Date" object you create.
-
- The "static" keyword can be used to change this, as in the "MonthMax" variable. There will be
- exactly one of those integers, no matter how many "Date" objects there are. This makes it a
- good place to store general information that applies to the entire class, rather than to
- individual objects of the class.
-
- "static" can be used for methods as well, and has a similar effect. It means the method
- applies to the entire class, not to an individual object.
- *Stream
- A "stream" is a way of treating a disk file. It looks at the file as a "stream" of bytes, and
- allows you to read through that stream in order from the first byte through to the last.
- *String
- This is one of the standard Java classes, and it allows you to work with character strings.
-
- For example:
-
- String a = "abc";
-
- This will create a String object, give it a value of "abc", and assign variable "a" to reference
- it.
-
- The String class includes a variety of methods that allow you to manipulate the string. For
- futher information, see Lesson 11. For information about how the "==" and "!=" operators
- work with Strings, see lesson 9.
- *Synchronized
- If your class has multiple threads, each thread can be executing independently of the others. This
- is fine, for the most part, but can be a problem if you want to be sure that only one of the
- threads is performing some critical task at once. For example, you might have a bunch of threads
- which are processing requests from a queue. Naturally, you only want one of the threads removing
- a request from the queue at once. (Otherwise, two threads might end up processing the same
- request.)
-
- This sort of protection can be added to a program by making a critical piece of code (like
- removing a request from a queue) "synchronized". By making a piece of code synchronized,
- Java will insure that only one thread at a time executes it.
-
- There are two ways to make code synchronized. One is by adding the "synchronized"
- keyword to a method header, and the other is by using the "synchronized" statement. Both
- methods are described in more detail in Lesson 10.
- *Switch
- The "switch" statement allows a Java program to select one piece of code from
- among several pieces of code based on the value of a variable. For example:
-
- switch (a) {
-
- case 1:
- b = 5;
- break;
-
- case 4:
- b = 6;
- c = 9;
- break;
-
- default:
- b = 7;
- break;
-
- }
-
- This statement will execute one of the three pieces of code listed, based
- on the value of "a". If "a" is 1, the first piece of code will be executed. If
- "a" is 4, the second piece will be executed. If "a" has any other value, the
- third piece will be executed.
- *Talk Java to Me
- This is the title of an instructional CD-ROM which teaches Java
- programming. Its name comes from the fact that the CD-ROM teaches
- by having narrators TALK to you, to explain the language. This is
- the simplest, most natural way to learn, and is a departure from
- many instructional CD-ROMS which require the user to read large
- quantities of text from the screen.
- *Telecommunications
- A bit far-fetched.
- *Thread
- A program often has just one "thread", but can have several. A "thread" is sort
- of like a separate copy of the program that's running, but all the copies
- use the same variables. Each "thread" runs independently
- of the other threads, and runs at the same time. This can allow
- different parts of the program to be running simultaneously, or can allow the same part
- of the program to be running more than once simultaneously.
-
- For more information on "threads", see Lessons 5 and 11.
- *Variable
- This is a location where data can be stored.
-
- There are two types of variables. The first, "field variables", are variables
- that are part of an object. For example, "month" in the following class
- definition is a "field variable":
-
- public class Date {
-
- int year;
- int month;
- int day;
-
- }
-
- The other type of variable is a "local variable". This is a variable created
- temporarily during the execution of a method. For example, "sum" is a
- local variable in the following method:
-
- int calcSum(int a) {
-
- int sum = 0;
- int i;
-
- for (i=0; i<a; ++i) {
- sum += i;
- }
-
- return sum;
-
- }
- *Vector
- A "vector" is another way of saying "array". It is simply a series of
- values, that are treated as a group. For example, you might have a
- vector that is 10 integers, each of which represents the age of an employee. You could
- declare the vector like this:
-
- int ages[10] = {18,18,35,53,39,39,27,44,42,60};
-
- You could calculate the average age like this:
-
- float average;
- int sum = 0;
- int i;
-
- for (i=0; i<10; ++i) {
- sum += ages[i];
- }
-
- average = sum / 10;
-
- In addition to being a synonym for "array", "vector" can also refer to
- an object of the "Vector" class. The "vector" class is one of the standard
- Java classes, and provides a way to create arrays that can have varying sizes.
- *While
- This is one of the looping statements in Java. For example:
-
- while (i < 10) {
- sum *= 1.01;
- ++i;
- }
-
- This will cause the statements "sum *= 1.01;" and "++i;" to be executed over and
- over, as long as "i" remains less than "10".
-
- A similar loop is:
-
- do {
- sum *= 1.01;
- ++i;
- } while (i < 10);
-
- The second loop is almost idential to the first. The only difference is that the
- second loop will always execute the statements "sum *= 1.01;" and "++i" at least once,
- regardless of the initial value of "i". The first loop, on the other hand, would
- never execute the statements if "i" is at least 10 when the loop begins.
- *End
-